package com.seng.userservice.service.impl;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.seng.userservice.entity.AliMsgEntity;
import com.seng.userservice.service.AliMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AliMsgServiceImpl implements AliMsgService {
    @Autowired
    private AliMsgEntity aliMsgEntity;

    @Override
    public boolean SendSms(String PhoneNumber, String TemplateParam) {
        CommonResponse response =null;
                DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4GEL9w3bGNLNNexeSrEX", "51bGbd6oHFW8DfVTRcHHuSUF0I30Rj");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", aliMsgEntity.getRegionId());
        request.putQueryParameter("PhoneNumbers", PhoneNumber);
        request.putQueryParameter("SignName", aliMsgEntity.getSignName());
        request.putQueryParameter("TemplateCode", aliMsgEntity.getTemplateCode());
        request.putQueryParameter("TemplateParam", TemplateParam);
        try {
             response = client.getCommonResponse(request);
             System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
            return true;
    }
}
